package itheima.com.exam.zy6;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class Test {
    public static void main(String[] args) {
        //    1. 请将下面人员信息按以下顺序存放至一个ArrayList集合中，要求定义一个标准类Person

        ArrayList<Person> arrayList = new ArrayList<>();
arrayList.add(new Person("张成",28,"甘肃"));
arrayList.add(new Person("刘安",37,"宁夏"));
arrayList.add(new Person("刘墉",40,"山东"));
arrayList.add(new Person("和珅",35,"北京"));
arrayList.add(new Person("和二",36,"北京"));
arrayList.add(new Person("纪晓岚",39,"山西"));
arrayList.add(new Person("刘安",37,"宁夏"));

//2. 要求随机输出一个人员信息
        int index = (int)(Math.random()*arrayList.size());
        Person person = arrayList.get(index);
        System.out.println(person);
        System.out.println("-----------------");

//3. 删除该集合中和姓人员
        Iterator<Person> it = arrayList.iterator();
        while (it.hasNext()) {
            if (it.next().getName().startsWith("和")) {
                it.remove();
            }
        }
        System.out.println("===================");


//4. 如集合中有重复人员，请去掉重复人员信息(要求采用Set集合)
        Set<Person> set = new HashSet<>();
        for (int i = 0; i < arrayList.size(); i++) {
            Person p = arrayList.get(i);
            set.add(p);
        }
        System.out.println(set);
        System.out.println("===================");

//5. 修改纪晓岚的地址信息为河北
        for (int i = 0; i < arrayList.size(); i++){
            Person p = arrayList.get(i);
            if (p.getName().equals("纪晓岚")){
                p.setAddress("河北");
            }
        }
        System.out.println("=============");
//6. 打印输出大于35岁的所有人员信息
        for (int i = 0; i < arrayList.size(); i++){
            Person p = arrayList.get(i);
            if (p.getAge() > 35){
                System.out.println(p);
            }
        }
    }
}
